package com.yhn.init.bizmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.yhn.init.constant.MQConstant;

/**
 * 声明队列和交换机
 *
 * @author yhnyhn123
 */
public class RabbitMqInitDemo {
    public static void main(String[] args) {
        try {
            ConnectionFactory factory = new ConnectionFactory();
            // 设置 rabbitmq 对应的信息
            factory.setHost("47.109.81.239");
            factory.setUsername("yhnyhn123");
            factory.setPassword("1658450511");

            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();

            String furnitureExchange = MQConstant.ORDER_EXCHANGE_NAME;

            channel.exchangeDeclare(furnitureExchange, "direct");

            // 创建队列，分配一个队列名称：小紫
            String queueName = MQConstant.ORDER_QUEUE_NAME;
            channel.queueDeclare(queueName, true, false, false, null);
            channel.queueBind(queueName, furnitureExchange, MQConstant.ORDER_ROUTING_KEY);

        } catch (Exception e) {

        }
    }

}
